How to Remove Dashes in Excel?

您所在的位置:网站首页 how to remove dotted lines in microsoft excel How to Remove Dashes in Excel?

How to Remove Dashes in Excel?

2023-10-26 06:30| 来源: 网络整理| 查看: 265

Get FREE Advanced Excel Exercises with Solutions!

Sometimes, we want to check certain values without dashes to have a deeper understanding of the information. But when the data are huge, it is not a wise way to remove dashes manually. In this article, you will learn how to remove dashes in Excel in the three most efficient ways.

Table of Contents hide How to Remove Dashes in Excel: 3 Methods 1. Find & Replace Command to Delete Dashes 2. Formula to Erase Dashes in Excel 3. Embed VBA Code to Remove Dashes Conclusion Related Articles How to Remove Dashes in Excel: 3 Methods

This section will discuss the methods of removing dashes in Excel by utilizing the Find & Replace command in Excel, by using the SUBSTITUTE function, and by implementing VBA code.

1. Find & Replace Command to Delete Dashes

The Find & Replace command is the easiest and the most common feature to do most of the Excel-related tasks. Here, we will get to know how to delete dashes by using the Find & Replace feature in Excel.

The steps to take are given below,

Step 1:

Select the dataset. Under the Home tab, go to Find & Select -> Replace.

remove dashes in excel by find & replace

Step 2:

From the pop-up Find and Replace box, in the Find what field, write the dash (-) symbol. Leave the Replace with field blank. Press Replace All.

remove dashes in excel by replacing with blank string

This will erase all the dashes from your dataset in Excel.

Notes: There is a major drawback in using the Find & Replace command to remove dashes in Excel. When your data starts with number zero (0) (for example, 002-10-2324), it will remove all the leading zeros and give you an output of modified data (for example, 002-10-2324 will become 2102324). So if you want to use the Find & Replace command to delete dashes, make sure that you have a backup copy of the original data.

Read more: How to Remove Semicolon in Excel

2. Formula to Erase Dashes in Excel

Unlike the Find & Replace command feature in Excel, using formula is the safest and the most controlled way to extract any kind of results in Excel. To get the output of a dataset without dashes in Excel, you can implement the SUBSTITUTE function.

Generic SUBSTITUTE Formula,

=SUBSTITUTE(cell, “old_string”, “new_string”)

Here,old_text = the string you want to remove.new_text = the string that you want to replace with.

Steps to remove dashes in Excel with the SUBSTITUTE function are given below,

Step 1:

In an empty cell where you want your result to appear, first put an equal (=) sign and then write SUBSTITUTE along with it. Inside the brackets of the SUBSTITUTE function, first write the cell reference number from which you want to remove the dash (-) (in our case, the cell number was C5). Then put a comma (,) symbol and after that, write a dash (-) symbol inside double quotes (or any old text that you want to remove). Again put a comma (,), and lastly, leave blank double quotes if you want a null string instead of a dash (-) (or any new string that you want your old text to replace with).

So, our required formula will look like the following,

=SUBSTITUTE(C5,”-”,””) Press Enter.

remove dashes in excel by formula

It will replace dashes (-) (or any other text that you selected) with a null string (or the string that you replace it with).

Step 2: Drag the row down using the Fill Handle to apply the formula to the rest of the dataset.

Now you have found the result of a dataset without any dashes (-).

Read more: How to Remove the Last 3 Characters in Excel

3. Embed VBA Code to Remove Dashes

If you are an experienced Excel user, then this method is only for you. Using VBA to remove dashes is the quickest and the absolute way to get the job done.

Step 1: Press Alt + F11 on your keyboard or go to the tab Developer -> Visual Basic to open Visual Basic Editor.

Step 2: In the pop-up code window, from the menu bar, click Insert -> Module.

Step 3: Copy the following code and paste it into the code window.

Sub RemoveDashes() Dim R As range Dim W As range On Error Resume Next xTitleId = "Excel" Set W = Application.Selection Set W = Application.InputBox("Range", xTitleId, W.Address, Type:=8) Application.ScreenUpdating = False For Each R In W     R.NumberFormat = "@"     R.Value = VBA.Replace(R.Value, "-", "") Next Application.ScreenUpdating = True End Sub

Your code is now ready to run.

Step 4: Press F5 on your keyboard or from the menu bar select Run -> Run Sub/UserForm. You can also just click on the small Play icon in the sub-menu bar to run the macro.

VBA code to remove dashes in excel

Step 5: From the pop-up Macro window, select the Macro Name RemoveDashes -> Run.

Step 6: From the pop-up dialogue box, switch to the worksheet of interest, select the desired range, and click OK.

dataset of removed dashes in excel by VBA

This will replace all the dashes (-) in your dataset with a null string.

If you want to replace any other text with something else with VBA code, then just modify line no. 11 of the code according to your need.

To understand more,

Instead of writing the line as,

R.Value = VBA.Replace(R.Value, "-", "")

Write it as,

R.Value = VBA.Replace(R.Value, "old_text", "new_text")

Here,

old_text = the string you want to remove.

new_text = the string that you want to replace with.

Read more: How to Remove First 3 Characters in Excel

Download Practice Workbook

You can download the free practice Excel template from here and practice on your own.

Remove Dashes in Excel.xlsm

Conclusion

This article discusses the methods of removing dashes in Excel by utilizing the Find & Replace command for beginners in Excel, by using the safest method of SUBSTITUTE formula for advanced users of Excel, and by implementing VBA code for Excel experts. I hope this article has been very beneficial to you. Feel free to ask any questions you have regarding the topic.

Related Articles Excel Remove Characters From Right How to Remove First Character in Excel How to Remove Apostrophe in Excel How to Remove Specific Characters in Excel How to Remove Asterisk in Excel How to Remove Blank Characters in Excel How to Remove Non-Printable Characters in Excel  How to Remove Characters from String Using VBA in Excel How to Remove Last Character from String Using VBA in Excel How to Remove the First Character from a String in Excel with VBA How to Remove Parentheses in Excel How to Remove Dashes from Phone Number in Excel How to Remove Dashes from SSN in Excel How to Remove Non-Alphanumeric Characters in Excel How to Remove Characters from Left in Excel How to Remove Characters from Left and Right in Excel How to Remove Last Character in Excel How to Remove Last Digit in Excel How to Remove Characters After a Specific Character in Excel How to Remove Special Characters in Excel How to Remove Numeric Characters from Cells in Excel How to Remove Non-numeric Characters from Cells in Excel SaveSavedRemoved 0

Tags: Excel Remove Characters

Sanjida Ahmed Sanjida Ahmed class="mb10">

Hello World! This is Sanjida, an Engineer who is passionate about researching real-world problems and inventing solutions that haven’t been discovered yet. Here, I try to deliver the results with explanations of Excel-related problems, where most of my interpretations will be provided to you in the form of Visual Basic for Applications (VBA) programming language. Being a programmer and a constant solution seeker, made me interested in assisting the world with top-notch innovations and evaluations of data analysis.

We will be happy to hear your thoughts Leave a reply Cancel reply


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3